import request from '.'

export const getNewsPool = async (data: any) => {
    const result = await request.get('/news/newsList?' + data)
    return result
}

export const getReleaseList = async (params?: string) => {
    const result = await request.post('/news/releaseList', params)
    return result
}

// export const updateNews = async (data: { id: number;[key: string]: any }) => {
//     const { access_token } = JSON.parse(localStorage.getItem('login')!)
//     const result = await request.post('/news/updateNews', data, {
//         headers: {
//             "Authorization": `Bearer ${access_token}`
//         }
//     })
//     return result
// }

export const getAcounts = async () => {
    const result = await request.post('/news/selectAllCountClassReal')
    return result.data
}

interface INews {
    id?: number;
    newsTitle?: string;
    title?: string;
    abstractReal: string;
    classReal: number;
    classModel?: string;
    newsSource?: string;
    newsTime?: string;
    coverImage?: string;
    isSelect?: number;
    addMode: number;
    siteName?: string;
    opPerson?: string;
    createTime?: string;
    pubTime?: string;
    isPublished?: number;
    markContent?: string;
    sourceUrl?: string;
}
export const createNews = <T>(data: Omit<INews,'id'>) => {
    return request.post('/news/insertNews', data) as Promise<T>
}

export const updateNews = <T>(data:Partial<INews> & { id: number }) => {
    const { access_token } = JSON.parse(localStorage.getItem('login')!)
    const result = request.post('/news/updateNews', data, {
        headers: {
            "Authorization": `Bearer ${access_token}`
        }
    })
    return result
}